import { datashopAxios } from '@/utils/request'

// 获取用户列表
export const getAllUserList = (params: any = {}): Promise<any> => {
  return datashopAxios({
    url: '/api/datashop/v3/users',
    method: 'get',
    params: {
      page: 1,
      page_size: 10,
      ...params
    }
  }).then((res: any) =>
    res.items.map((item: any) => ({
      label: item.name,
      value: item.id
    }))
  )
}

// 新-获取关联项目名称
export const getAllNewProjectList = (params: any = {}): Promise<any> => {
  return datashopAxios({
    url: `/api/project/v2/projects/project_options`,
    method: 'get',
    params: {
      page: 1,
      page_size: 10,
      do_page: true,
      ...params
    }
  }).then((res) =>
    res.items.map((item: any) => ({
      label: item.name,
      value: item.id
    }))
  )
}
// 获取关联项目名称
export const getAllProjectOptions = (): Promise<any> => {
  return datashopAxios({
    url: `/api/project/v2/projects/project_options`,
    method: 'get',
    params: {
      page: 1,
      page_size: 99999,
      do_page: false
    }
  }).then((res) =>
    res.map((item: any) => ({
      label: item.name,
      value: item.id
    }))
  )
}

// 新-添加项目
export const addNewOrderProject = (data: any) => {
  return datashopAxios({
    url: '/api/project/v2/projects',
    method: 'post',
    data
  })
}

// 数据主题
export const getAllThemeList = (params: any = {}): Promise<any> => {
  return datashopAxios({
    url: '/api/datashop/v3/data-topics',
    method: 'get',
    params: {
      page: 1,
      page_size: 10,
      status: 'published',
      ...params
    }
  }).then((res: any) =>
    res.items.map((item: any) => ({
      label: item.name,
      value: item.id
    }))
  )
}

// 数据项列表
export const getDataItemList = (params: any): Promise<any> => {
  return datashopAxios({
    url: '/api/datashop/v3/data-item-products',
    method: 'get',
    params: {
      page: 1,
      page_size: 10,
      status: 'published',
      ...params
    }
  }).then((res: any) =>
    res.items.map((item: any) => ({
      label: item.name,
      value: item.id
    }))
  )
}

// 领域列表
export const getDomainList = (params: any): Promise<any> => {
  return datashopAxios({
    url: '/api/datashop/v3/industry-domains',
    method: 'get',
    params: {
      page: 1,
      page_size: 10,
      status: 'published',
      ...params
    }
  }).then((res: any) => ({
    items: res.items.map((item: any) => ({
      label: item.name,
      value: item.id
    })),
    total: res.total
  }))
}

// 领域列表
export const getSelectCategoryList = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/tags`,
    method: 'get',
    params: {
      page: 1,
      page_size: 10,
      ...params
    }
  }).then((res: any) => ({
    items: res.items.map((item: any) => ({
      label: item.name,
      value: item.id
    })),
    total: res.total
  }))
}
